class: title-slide # ER018 - Analyzing Business Relations & Documents ## PVA3 ### Analyse Räumlicher Daten in R <br> <br> <br> <br> <br> <br> <br> ### FS 2024 <br> ### Prof. Dr. Jörg Schoder .mycontacts[
@FFHS-EconomicResearch
@jfschoder ] --- layout: true <div class="my-footer"></div> <div style="position: absolute;left:400px;bottom:10px;font-size:9px">
Prof. Dr. Jörg Schoder</div> --- name: agenda class: left .blockquote[Agenda] ## Analyse Räumlicher Daten in R * Überblick Bibliotheken * Karten erstellen * Räumliche Regression * Räumliche Netzwerke ??? [Beispiel](https://crd230.github.io/lab9.html) [Scott](https://www.esri.com/news/arcwatch/0410/lauren-scott.html) --- class: inverse, center, middle ## Kartenerstellung in R .blockquote[Vektordaten und shapefiles] .blockquote[simple features und das sf-Paket] .blockquote[Schweizer Geodaten] .blockquote[Kartierung mit ggplot] .blockquote[Interaktive Karten mit Leaflet] --- class: left .blockquote[] ## Dateiformate für räumliche Daten .pull-left[ <img src="data:image/png;base64,#../../img/PVA3/Vektordaten_Dateiformate_(SurveyGyaan_2022)_medium.PNG" width="100%" style="display: block; margin: auto;" /> ] -- .pull-right[ <img src="data:image/png;base64,#../../img/PVA3/Rasterdaten_Dateiformate_(SurveyGyaan_2022)_medium.PNG" width="100%" style="display: block; margin: auto;" /> ] .quelle[Quelle: <a name=cite-surveygyaan_vector_2022></a>[Surveygyaan (2022)](#bib-surveygyaan_vector_2022), .] --- class: left .blockquote[sf-Paket] ## Warum das sf-Paket? * Schnelles Lesen und Schreiben von Daten -- * Verbesserte Leistung beim Plotten -- * Verwendung von `sf`-Objekten (in der Regel) wie `data.frame`- oder `tibble-Objekte` -- * konsistente und intuitive Verben als Funktionsnamen (beginnen mit `st_`) -- * Kompatibilität mit tidyverse-Synatax und Verwendung mit Pipes --- class: left ## Simple Karte .panelset[ .panel[.panel-name[Top5 CH-Städte] ```r library(tidyverse) ``` ``` ## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── ## ✔ dplyr 1.1.4 ✔ readr 2.1.5 ## ✔ forcats 1.0.0 ✔ stringr 1.5.1 ## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1 ## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1 ## ✔ purrr 1.0.2 ## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ── ## ✖ dplyr::filter() masks stats::filter() ## ✖ dplyr::lag() masks stats::lag() ## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors ``` ```r my_in_file <- "CitiesCH_(simplemaps.com).csv" tbl_citiesCH <- read_csv(xfun::from_root("data","raw","PVA3",my_in_file)) ``` ``` ## Rows: 177 Columns: 9 ## ── Column specification ──────────────────────────────────────────────────────── ## Delimiter: "," ## chr (5): city, country, iso2, admin_name, capital ## dbl (4): lat, lng, population, population_proper ## ## ℹ Use `spec()` to retrieve the full column specification for this data. ## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. ``` ```r tbl_citiesCH5 <- tbl_citiesCH %>% arrange(desc(population)) %>% slice_head(n=5) tbl_citiesCH ``` ``` ## # A tibble: 177 × 9 ## city lat lng country iso2 admin_name capital population ## <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <dbl> ## 1 Zürich 47.4 8.54 Switzerland CH Zürich admin 447082 ## 2 Geneva 46.2 6.15 Switzerland CH Genève admin 203840 ## 3 Basel 47.6 7.59 Switzerland CH Basel-Stadt admin 173552 ## 4 Lausanne 46.5 6.63 Switzerland CH Vaud admin 141418 ## 5 Bern 46.9 7.45 Switzerland CH Bern primary 134506 ## 6 Winterthur 47.5 8.73 Switzerland CH Zürich minor 109775 ## 7 Lucerne 47.0 8.3 Switzerland CH Luzern admin 81691 ## 8 Sankt Gallen 47.4 9.37 Switzerland CH Sankt Gallen admin 75833 ## 9 Biel/Bienne 47.1 7.25 Switzerland CH Bern <NA> 55159 ## 10 Bellinzona 46.2 9.03 Switzerland CH Ticino admin 43785 ## # ℹ 167 more rows ## # ℹ 1 more variable: population_proper <dbl> ``` ] .panel[.panel-name[Einfache Abbildung] ```r tbl_citiesCH5 %>% ggplot(aes(x = lng, y = lat)) + geom_point() ``` <!-- --> ] .panel[.panel-name[Labels ergänzen] ```r tbl_citiesCH5 %>% ggplot(aes(x = lng, y = lat)) + geom_point() + geom_text(aes(label=city),hjust=1, vjust=-0.5) + scale_x_continuous(limits = c(5.5,9)) ``` <!-- --> ] .panel[.panel-name[Gewichtung] ```r tbl_citiesCH5 %>% ggplot(aes(x = lng, y = lat)) + geom_point(aes(size=population)) + geom_text(aes(label=city),hjust=1, vjust=-0.5) + scale_x_continuous(limits = c(5.5,9)) ``` <!-- --> ] ] --- class: left .blockquote[Kartenerstellung] ## Schweiz ```r library(ggswissmaps) ggswissmaps::maps2 ``` ``` ## $g1b15 ``` <!-- --> ``` ## ## $g1g15_encl ``` <!-- --> ``` ## ## $g1g15_li ``` <!-- --> ``` ## ## $g1g15 ``` <!-- --> ``` ## ## $g1k15 ``` <!-- --> ``` ## ## $g1l15 ``` <!-- --> ``` ## ## $g1r15 ``` <!-- --> ``` ## ## $g1s15 ``` <!-- --> <!-- --> ??? [swissgd](https://github.com/zumbov2/swissgd) [bfsMaps](https://cran.r-project.org/web/packages/bfsMaps/bfsMaps.pdf) [RSwissMaps](https://github.com/zumbov2/RSwissMaps) aktuell noch nicht verfügbar für R4.4.0 --- class: left ```r library(geojsonsf) #sf <- geojson_sf("https://data.sbb.ch/api/explore/v2.1/catalog/datasets/linie-mit-polygon/exports/geojson") sf_london <- geojson_sf(xfun::from_root("data","raw","PVA3","london_421.geojson")) sf_zh <- geojson_sf(xfun::from_root("data","raw","PVA3","zurich-small_.geojson")) p_zh <- sf_zh %>% ggplot2::ggplot() + geom_sf() + theme_void() p_ld <- sf_london %>% ggplot2::ggplot() + geom_sf() + theme_void() library(patchwork) p_zh+p_ld ``` <!-- --> ??? Quelle: [](https://cartographyvectors.com/map/421-london#google_vignette) --- class: left ## Starbucks Zürich ```r library(tidyverse) tbl_starbucks <- read_csv(xfun::from_root("data","raw","PVA3","starbucks_(kaggle).zip")) starbucks_zh <- tbl_starbucks %>% filter(City=="Zurich"&Country=="CH") ``` --- class: left .blockquote[Räumliche Autokorrelation] ## Kennzahlen Räumliche Autokorrelation * Moran ??? Griffith, Enzyklopädie GIS --- class: inverse, center, middle ## Räumliche Autokorrelation .blockquote[] .blockquote[] ??? --- class: inverse, center, middle ## Räumliche Statistik vs. Geostatistik .blockquote[] .blockquote[] --- class: left ## Zusammenfassung <img src="data:image/png;base64,#../../img/PVA3/Geostats_(Emery_Seguret)_Sxxi.PNG" width="50%" style="display: block; margin: auto;" /> .quelle[Quelle: <a name=cite-seguret_geostatistics_2021></a>[Séguret and Emery (2021)](#bib-seguret_geostatistics_2021), S. xxi.] --- class: inverse,center,middle # Wir brauchen eine Pause. --- background-image: url("data:image/png;base64,#http://bit.ly/cs631-donkey") background-size: 80% --- class: left ## Quellenverzeichnis .ref-slide[ <a name=bib-seguret_geostatistics_2021></a>[Séguret, S. A. and X. Emery](#cite-seguret_geostatistics_2021) (2021). _Geostatistics for the Mining Industry: Applications to Porphyry Copper Deposits_. Boca Raton London New York: CRC Press, Taylor and Francis Group. ISBN: 978-0-367-50575-2. <a name=bib-surveygyaan_vector_2022></a>[Surveygyaan](#cite-surveygyaan_vector_2022) (2022). _Vector Data in GIS_. (Visited on Mai. 21, 2024). ]